package com.lucun.es_transaction.controller;

import com.lucun.es_transaction.config.RolePermission;
import com.lucun.es_transaction.entity.Admin;
import com.lucun.es_transaction.service.AdminService;
import com.lucun.es_transaction.util.AuthorityUtil;
import com.lucun.es_transaction.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    AdminService adminService;

    /*
     * 查询所有
     * */
    @RolePermission(login = false)
    @RequestMapping("/findAll")
    public List<Admin> FindAll() {
        return adminService.findAll();
    }

    /*
     * 添加数据
     * */
    @RolePermission(role = AuthorityUtil.FIRST)
    @RequestMapping("/index")
    public JsonResult<?> Index(@RequestBody Admin record, HttpServletRequest request) {
        return adminService.insert(record, request);
    }

    //    /*
//    * 修改
//    * */
    @RolePermission(role = AuthorityUtil.FIRST)
    @RequestMapping("/update")
    public JsonResult Update(@RequestBody Admin record, HttpServletRequest request) {
        return adminService.updateByPrimaryKeySelective(record, request);
    }

    /*
     * 根据adminNumber查询
     * */
    @RolePermission(role = AuthorityUtil.THIRD)
    @RequestMapping("/selectByNumber")
    public JsonResult<?> SelectByNumber(HttpServletRequest request) {
        return adminService.findByNumber(request);
    }

    //删除
    @RolePermission(role = AuthorityUtil.FIRST)
    @RequestMapping("/delete")
    public JsonResult Delete(int id, HttpServletRequest request) {
        return adminService.deleteByPrimaryKey(id, request);
    }
}
